package com.chorye.redis.controller;

import com.chorye.redis.entity.Student;
import com.chorye.redis.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @Company: 北京XXXX有限公司
 * @Author JiangYy
 * @Title: StudentController
 * @Description: TODO
 * @Date 2018/12/24 13:47
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    /**
     * 保存学生
     *
     * @return 成功信息
     */
    @RequestMapping("/save")
    public String save() {
        Student student = new Student();
        student.setId(1);
        student.setName("redis测试");
        student.setBirth(new Date());
        student.setSalary(BigDecimal.valueOf(1000));
        studentService.save(student);
        return "保存成功";
    }

    /**
     * 获取学生信息
     *
     * @param id 学生id
     * @return 学生信息
     */
    @RequestMapping("/read")
    public Student read(String id) {
        return studentService.read(id);
    }
}
